package com.shupian.service.impl;

import com.shupian.service.PermissionService;
import com.shupian.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Service("ps")
public class PermissionServiceImpl implements PermissionService {

    /**
     * 判断当前用户是否具有permisson
     * @param permission
     * @return
     */
    public boolean hasPermission(String permission){
        //如果是超级管理员直接返回true
        if(SecurityUtils.isAdmin()){
            return true;
        }
        //否则获取当前用户所具有的权限列表 判断是否有permission
        List<String> permissions = SecurityUtils.getLoginUser().getPermissions();
        if(ObjectUtils.isEmpty(permissions)){
            return false;
        }
        return permissions.contains(permission);
    }
}
